<template>
  <el-select v-model="brandId" placeholder="请选择品牌" @change="changeBrand">
    <el-option
      v-for="(item,index) in brandList"
      :key="index"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
</template>

<script>
export default {
  name: 'SupplierBrandBox',
  props:{
    setCallBack:Function,
    initBrand:Number
  },
  data:function () {
    return {
      classifyId:0,
      brandList:[],
      brandId:''
    }
  },
  mounted () {
    this.brandId=this.$props.initBrand?this.$props.initBrand:''
    console.log('this.brandId',this.brandId)
    this.getList()
  },
  methods:{
    // 设置分类ID
    setClassifyId:function (classifyId) {
      this.classifyId=classifyId
      this.brandId=''
      this.$props.setCallBack(this.brandId)
      this.getList()
    },
    // 更改品牌
    changeBrand:function () {
      if (typeof this.$props.setCallBack==='function'){
        this.$props.setCallBack(this.brandId)
      }
    },
    // 获取店铺所有品牌
    getList:function () {
      let $this=this
      $this.loading=true
      $this.MyRequest($this.ApiDoNameSupplier+'Product/getBrandList',{isAll:true},function (list) {
        $this.loading=false
        $this.brandList=list
        $this.$forceUpdate()
      },function (res) {
        $this.$message.error(res.message)
        $this.loading=false
      })
    }
  }
}
</script>

<style scoped>

</style>
